package net.ojbk.study.curriculumDesign.web.handlers.cilentservicer.impl;

import net.ojbk.study.curriculumDesign.beans.usermanage.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/1/9
 * Time: 21:09
 * Description: No Description
 */
@RequestMapping("/cilentservicer")
@Controller
public class TestController {
    @RequestMapping("login")
    public ResponseEntity<Object> login(HttpSession session, String uid) {
        User user = new User(uid);
        session.setAttribute("user", user);
        return new ResponseEntity<Object>(user, HttpStatus.OK);
    }

    @RequestMapping(value = "uid", method = RequestMethod.GET)
    public ResponseEntity<Object> getUid(HttpSession session) {
        User user = (User) session.getAttribute("user");
        return new ResponseEntity<Object>(user == null ? null : user.getUid(), HttpStatus.OK);
    }
}
